import { useReducer } from 'react';

export interface IResourcesAllState {
  resourCurrent: number;
}

interface IActionType {
  type: 'chanage-current';
  payload: any;
}

export const useResourcesReducer = () => {
  const initState: IResourcesAllState = {
    resourCurrent: 0,
  };

  const reducer = (state: IResourcesAllState, actions: IActionType) => {
    switch (actions?.type) {
      case 'chanage-current':
        return {
          ...state,
          resourCurrent: actions?.payload,
        };
      default:
        return {
          ...state,
        };
    }
  };

  const [state, commonDispatch] = useReducer(reducer, initState);

  return {
    ...state,
    commonDispatch,
  };
};
